package com.wyl.customui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.fragment.app.Fragment
import kotlinx.android.synthetic.main.fragment_flow_layout_simple.*

class FlowLayoutSimpleFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_flow_layout_simple, container, false)
    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val items = mutableListOf(
            "鼠标", "键盘", "显示器", "路由器", "笔记本", "音响", "主机",
            "鼠标2", "键盘2", "显示器2",
            "路由器2路由器2路由器2路由器2路由器",
            "笔记本2", "音响2", "主机2"
        )

        flowLayout.setItems(items)
        flowLayout.onItemClickListener = { _, text ->
            Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
        }
        testNet(items)
    }

    private fun testNet(items: MutableList<String>) {
//        //往容器内添加TextView数据
//        val layoutParams = LinearLayout.LayoutParams(
//            ViewGroup.LayoutParams.WRAP_CONTENT,
//            ViewGroup.LayoutParams.WRAP_CONTENT
//        )
//        layoutParams.setMargins(10, 5, 10, 5);
//        if (flowLayout != null) {
//            flowLayout.removeAllViews();
//        }
//
//
//        items.forEach {
//            val tv = TextView(requireContext())
//            tv.setPadding(28, 10, 28, 10);
//            tv.setText(it);
//            tv.setMaxEms(10);
//            tv.setSingleLine();
//            tv.setLayoutParams(layoutParams);
//            flowLayout.addView(tv, layoutParams);
//        }
    }


}